/**
 * PackageDir: info.javafans.cdn.web.action
 * FileName: AddNewsAction.java
 * CreateDate: 2011-3-6 下午01:48:28
 * Copyright: Copyright (c) 2011 <br />
 * Company: fossd <br />
 * @author Yintao Xue
 * @version 1.0 2011-3-6
 */
package info.javafans.cdn.web.action;

import info.javafans.cdn.dao.NewsDao;
import info.javafans.cdn.domain.Member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Project: CollegeDatingNetwork <br />
 * ClassName: AddNewsAction <br />
 * Description:  <br />
 */
public class AddNewsAction extends Action {
	
	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String action = request.getParameter("action");
		if (action == null) {
			HttpSession session = request.getSession();
			Object o = session.getAttribute("member");
			
			ShowIndexAction.prepareDate(request, response);
			if (o == null) {
				return "error";
			}
			else {
				return "success";
			}
		} else if (action.equals("addnews")) {
			
		}
		 else if (action.equals("doadd")) {
			this.doAdd(request, response);
		} else {
		
		}
		return "error";
	}
	
	/**
	 * 添加新闻
	 * doAdd
	 * @param request
	 * @param response
	 * @return
	 */
	public String doAdd(HttpServletRequest request, HttpServletResponse response) {
		String topic = request.getParameter("topic");
		String content = request.getParameter("content");
		HttpSession session = request.getSession();
		Object o = session.getAttribute("member");
		Member m = (Member)o;
		NewsDao.addNews(topic, content, m.getId());
		
		return "success";
	}
	
}
